<?php

namespace app\model;

use think\Model;

class Menu extends Model
{
    protected $pk = 'id';

    /**
     * @param $value
     * @return mixed|string
     */
    public function getUrlAttr($value)
    {
        $array = empty($value) ? [] : explode(',', $value);

        if (!empty($array)) {
            $pageKey = array_search('page', $array);
            if ($pageKey !== false) {
                $value = '/' . $array[$pageKey + 1];

                if (isset($array[$pageKey + 2]) && strstr($array[$pageKey + 2], 'atype')) {
                    $value .= '?' . $array[3];
                }
            }
        }

        return $value;
    }
}